package com.bartender.consumer.service.impl;

import com.bartender.consumer.service.ITokenService;
import org.springframework.stereotype.Service;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

@Service
public class TokenServiceImpl implements ITokenService {
    private final String secretKey = "abcdefghijklmnopqrstuvwxyz";
    private final long expirationTime = 86400000; // 1天

    @Override
    public String createToken(String openid, String sessionKey) {
        return Jwts.builder()
                .setSubject(openid)
                .claim("sessionKey", sessionKey)
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis() + expirationTime))
                .signWith(SignatureAlgorithm.HS512, secretKey)
                .compact();
    }
} 